package xio.ccf_201604;

import java.util.Scanner;

/**
 * ccf 201604-2 俄罗斯方块 100
 * Created by ywb47 on 2017/9/28.
 */
public class Tetris {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        // 方格图
        int[][] src = new int[15][10];
        for (int i = 0; i < 15; i++) {
            for (int i1 = 0; i1 < 10; i1++) {
                src[i][i1] = sc.nextInt();
            }
        }

        //矩形方块
        int[][] box = new int[4][4];
        int boxStartIndex;
        for (int i = 0; i < 4; i++) {
            for (int i1 = 0; i1 < 4; i1++) {
                box[i][i1] = sc.nextInt();
            }
        }
        //矩形方块起始位置
        boxStartIndex = sc.nextInt();


        //矩形方块4个方块对应的横纵坐标
        int[] boxX =new int[4];
        int[] boxY =new int[4];
        int k = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (box[i][j] == 1) {
                    boxX[k] = i;
                    boxY[k] = j+boxStartIndex-1;
                    k++;
                }
            }
        }

        boolean flag = true;

        int count=0;
        int offset =0; //下沉位移
        outer:
        while(flag){
            for(int i=0;i<4;i++){  //4个方块 一个个检测对应在方格图中的位置是否有障碍 没有障碍 count++
                //判断最下面的边界,如果有一个方块到了最下面，直接结束下沉
                if((boxX[i]+offset)==14){
                    for(int j=0;j<4;j++){
                        src[boxX[j]+offset][boxY[j]]=1;
                    }
                    break outer;
                }
                if(src[boxX[i]+offset][boxY[i]]==0){
                    count++;
                }
            }
            if(count==4){  //4个即一行都无障碍 开始下一行
                offset++;
                count=0;
            }else{
                for(int i=0;i<4;i++){
                    src[boxX[i]+offset-1][boxY[i]]=1;
                }
                flag = false;
            }
        }

        //输出
        for (int i = 0; i < 15; i++) {
            for (int i1 = 0; i1 < 10; i1++) {
                System.out.print(src[i][i1]+" ");
            }
            System.out.print("\n");
        }



    }
}
